﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Automation;


namespace PokerStarsClientTools
{
    public partial class Form1 : Form
    {
        internal string PSClientTitleStart = "PokerStars Lobby - Logged in as Stef2001";
        internal string DebugClientTitleStart = "Microsoft";

        private MainPSWindow _mainPSWindow;
        

        /// <summary>
        /// The main Pokerstars Window
        /// </summary>
        public  MainPSWindow PsWindow { 
            get 
            {
                if (_mainPSWindow != null)
                    return _mainPSWindow;

                _mainPSWindow=new MainPSWindow(PSClientTitleStart);

                if (_mainPSWindow == null)
                    throw new Exception(string.Format("Window starting with <{0}> not found !", PSClientTitleStart));


                return _mainPSWindow;
                
            }
        }


      

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            DebugMsg("Starting");

         

        }



        private void DebugMsg(string message)
        {
            if(listBoxDebug.Items.Count>1000) listBoxDebug.Items.Clear();

            listBoxDebug.Items.Add(string.Format("{0} : {1}",DateTime.Now,  message));
            listBoxDebug.SelectedIndex = listBoxDebug.Items.Count - 1;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                DebugMsg("Pokerstars Window found : " + PsWindow.PsWindowsUI.Current.ClassName);

                

                


            }
            catch (Exception ex)
            {
                
                DebugMsg("ERROR : "+ ex.Message );
            }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {

            //foreach (White.Core.UIItems.WindowItems.Window table in MainPSWindow.OpenedTables)
            //{
            //    DebugMsg("Opened table found : " + table.Title);
            //}

        }

        private void btnAutoRegisterTRN_Click(object sender, EventArgs e)
        {
            try
            {
                //trying to get the current list of tourney in the lobby
                //AutomationElement listTourney=  this.PsWindow.CurrentTourneyLobbyList;

                DebugMsg("Register Button clickable : " + PsWindow.IsRegisterButtonClickable );

                //Listing the Tourney visibles in filter
                DebugMsg("Tourney List : " + PsWindow.LobbyTourneyList.ToString());
                


            }
            catch (Exception ex)
            {

                DebugMsg("ERROR : " + ex.Message);
            }
        }

        private void getDetailledStats_Click(object sender, EventArgs e)
        {

            

        }

    }
}
